$(function () {
    var product_datagrid = $("#product_datagrid");

    //商品列表初始化
    product_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        striped: true,
        url: "/product/listView.do",
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: "#tb",
        columns: [[
            {field: "cb", checkbox: true},
            {field: "id", hidden: true},
            {field: "sn", title: "商品编号", width: 80},
            {field: "name", title: "商品名称", width: 80},
            {field: "costPrice", title: "成本价", width: 80},
            {field: "salePrice", title: "销售价", width: 80},
            {
                field: "imgPath", title: "商品图", width: 80, formatter: imgformatter
            },
            {field: "remark", title: "备注", width: 80}
        ]]
    })
    //end


    //给按钮绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })

})


function imgformatter(value, row, index) {
    if (value) {
        return "<img src='" + value + "' style='width: 120px; height: 100px'>";
    }

}

function getCellValue() {

    var rows = $("#product_datagrid").datagrid('getRows');
    var imgPath = null;
    for (var i = 0; i < rows.length; i++) {

        imgPath = rows[i]['imgPath'];//获取指定列
    }
    return imgPath;
}








